import React from 'react';

class List extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            username: "jake"
        }
        this.getInputValue = this.getInputValue.bind(this)
    }

    getInputValue() {
        alert(this.state.username)
    }

    inputChange = ()=> {
        let value = this.refs.name.value
        console.log(value)
        this.setState({
            username: value
        })
    }

    inputKeyUp = (e)=> {
        console.log(e.keyCode)
        if (e.keyCode == 13) {
            console.log(e.target.value);
        }
    }

    render() { 
        return (
            <div className="App">
                <input ref="name" onChange={this.inputChange}/> <button onClick={this.getInputValue}>获取input值</button>
                <h2> 按回车获取值</h2>
                <input onKeyUp={this.inputKeyUp}/>
            </div>
          );
    }
}
 
export default List;

